<template>
  <el-container style="min-height: 100vh">

    <el-aside :width="sideWidth + 'px'" style="box-shadow: 2px 0 6px rgb(0 21 41 / 35%);">
       <Aside :isCollapse="isCollapse" :logoTextShow="logoTextShow" />
    </el-aside>

    <el-container>
      <el-header style="font-size: 12px; border-bottom: 1px solid #ccc; ">
        <Header :collapseBtnClass="collapseBtnClass" :collapse="collapse" />

      </el-header>

      <!-- 表示当前页面的子路由会在router-view展示 -->
      <el-main>
        <router-view @refreshUser="getUser" />
      </el-main>

    </el-container>
  </el-container>
</template>

<script>

import Aside from "@/components/Aside.vue"
import Header from "@/components/Header.vue"
import {getUser} from "@/utils/tools";


export default {
  name: 'Home',
  data() {
    return {
      collapseBtnClass: 'el-icon-s-fold',
      isCollapse: false,
      sideWidth: 200,
      logoTextShow: true,
      user:null// 这里存储用户信息
    }
  },
    components:{
    Aside,
    Header
  },
  created(){
    this.getUser()
  },
  methods: {
    collapse() {  // 点击收缩按钮触发
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {  // 收缩
        this.sideWidth = 64
        this.collapseBtnClass = 'el-icon-s-unfold'
        this.logoTextShow = false
      } else {   // 展开
        this.sideWidth = 200
        this.collapseBtnClass = 'el-icon-s-fold'
        this.logoTextShow = true
      }
    },
    getUser() {
      let loginName = getUser().loginName;
      if (loginName) {
        // 从后台获取User数据
        this.request.get("/sysuser/username/" + loginName).then(res => {
          // 重新赋值后台的最新User数据
          if (res.success) {
            this.user = res.data
          }
        })
      }
    }


  }

}
</script>